package com.example.demo.test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description TODO
 * @Author wzh
 * @Date 2022/6/7 9:24 下午
 * @Version 1.0
 */
public class Lc1 {
    public static void main(String[] args) {
        int[] nums = {2,7,11,15};
        System.out.println(Arrays.toString(twoSum(nums, 9)));
    }

    public static int[] twoSum(int[] nums, int target) {
        Map<Integer,Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if(!map.containsKey(nums[i])){
                map.put(target-nums[i],i);
            }else{
                return new int[]{map.get(nums[i]),i};
            }
        }
        return new int[0];
    }
}
